/*
 * @description:
 * @version: 1.0.1
 * @Author: xuqiulin
 * @Date: 2021-04-30 11:08:50
 * @LastEditors:
 * @LastEditTime: 2021-04-30 21:30:39
 */
package controllers

import (
	"GameServer/Game/union"
	"strconv"

	"github.com/gin-gonic/gin"
)

// @Summary 公会列表
// @Produce  json
// @Param page query int false "page"
// @Param pageNum query int false "pageNum"
// @Success 200 {string} json "{"code":0,"data":{},"msg":"ok"}"
// @Router /union/list [get]
func UnionList(c *gin.Context) {
	uid := c.DefaultQuery("uid", "")
	name := c.DefaultQuery("name", "")

	pageStr := c.DefaultQuery("page", "0")
	pageNumStr := c.DefaultQuery("pageNum", "10")

	page, _ := strconv.Atoi(pageStr)
	pageNum, _ := strconv.Atoi(pageNumStr)

	if page > 0 {
		page--
	}

	list, num := union.UnionModule.UnionListAll(page, pageNum, uid, name)
	mdata := make(map[string]interface{}, 0)
	mdata["num"] = num
	mdata["list"] = list
	handleOk(c, mdata)
}

// @Summary 公会信息
// @Produce  json
// @Param unionId path string true "unionId"
// @Success 200 {string} json "{"code":0,"data":{},"msg":"ok"}"
// @Router /union/info/{unionId} [get]
func UnionInfo(c *gin.Context) {
	id := c.Param("unionId")
	union, members, err := union.UnionModule.UnionInfo(id)
	if err != nil {
		handleOk(c, err.Error())
		return
	}
	mdata := make(map[string]interface{}, 0)
	memberList := make([]interface{}, 0)
	mdata["union"] = union
	for _, v := range members {
		memberList = append(memberList, v)
	}
	mdata["members"] = memberList
	handleOk(c, mdata)
}

// @Summary 工会成员信息
// @Produce  json
// @Param unionId path string true "unionId"
// @Success 200 {string} json "{"code":0,"data":[{},{}],"msg":"ok"}"
// @Router /union/members [get]
func UnionMemberList(c *gin.Context) {
	id := c.DefaultQuery("unionId", "")           //工会ID
	pageStr := c.DefaultQuery("page", "0")        //页码
	pageNumStr := c.DefaultQuery("pageNum", "10") //每页显示数量

	page, _ := strconv.Atoi(pageStr)
	pageNum, _ := strconv.Atoi(pageNumStr)
	//通过公会ID，获取公会所有成员。
	list, num := union.UnionModule.UnionMemberList(id, page, pageNum)
	mdata := make(map[string]interface{}, 0)
	mdata["list"] = list
	mdata["num"] = num
	handleOk(c, mdata)
}
